package com.longnuoqi.mydoctor.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;

import com.longnuoqi.mydoctor.activity.DoctorAskActivity;
import com.longnuoqi.mydoctor.activity.NearbyHospitalActivity;
import com.longnuoqi.mydoctor.activity.NewsContentActivity;
import com.longnuoqi.mydoctor.activity.ZizhenDiseaseActivity;
import com.longnuoqi.mydoctor.adapter.UserFavoriteListAdapter;
import com.longnuoqi.mydoctor.entity.Favorite;
import com.longnuoqi.mydoctor.widget.MyListView;
import com.yunhe.mydoctor.R;

import java.util.ArrayList;


/**
 * Created by Lenovo on 2016/1/11.
 */
public class UserFavoriteFragment extends Fragment {
    private View view;
    private MyListView listView;
    private ArrayList<Favorite> list;
    private UserFavoriteListAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.user_favorite_list, container, false);
        list = getArguments().getParcelableArrayList("favorite");
        initView(view);
        return view;
    }

    private void initView(View view) {
        listView = (MyListView) view.findViewById(R.id.user_favorite_listview);
        adapter = new UserFavoriteListAdapter(getActivity(), list);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String type = (String) (view.findViewById(R.id.user_favorite_lv_type)).getTag();
                int favoriteId = (Integer) (view.findViewById(R.id.user_favorite_lv_txt)).getTag();
                switch (type) {
                    case "ask":
                        Intent ask = new Intent(getActivity(), DoctorAskActivity.class);
                        ask.putExtra("id", favoriteId);
                        startActivityForResult(ask, 0);
                        break;
                    case "info":
                        Intent info = new Intent(getActivity(), NewsContentActivity.class);
                        info.putExtra("id", favoriteId);
                        startActivityForResult(info, 0);
                        break;
                    case "disease":
                        Intent disease = new Intent(getActivity(), ZizhenDiseaseActivity.class);
                        disease.putExtra("id", favoriteId);
                        startActivityForResult(disease, 0);
                        break;
                    case "hospital":
                        Intent hospital = new Intent(getActivity(), NearbyHospitalActivity.class);
                        hospital.putExtra("id", favoriteId);
                        startActivityForResult(hospital, 0);
                        break;
                    default:
                        break;
                }
            }
        });
    }
}
